/*
 *  CTutorialCPPEntity.cpp
 *
 *  C++ Entity impl
 */

#include "StdAfx.h"
#include "CTutorialCPPEntity.h"

bool
CTutorialCPPEntity::Init(IGameObject * pGameObject)
{
    SetGameObject(pGameObject);

	GetEntity()->Activate(true);

    return true;
}

void
CTutorialCPPEntity::PostInit(IGameObject * pGameObject)
{
	pGameObject->EnableUpdateSlot(this, 0);
	GetEntity()->LoadGeometry(0, "Objects/architecture/buildings/forest_ruin/forest_ruin.cgf");

	SEntityPhysicalizeParams physParams;

	physParams.mass = 500;
	physParams.type = PE_STATIC;

	GetEntity()->Physicalize(physParams);

    m_pmatDefault = gEnv->p3DEngine->GetMaterialManager()->LoadMaterial("materials/material_default");
    m_pmatOriginal = GetEntity()->GetMaterial();

    bMaterialSwitchedBack = false;
    GetEntity()->SetMaterial(m_pmatDefault);

}

void
CTutorialCPPEntity::Update(SEntityUpdateContext& ctx, int updateSlot)
{
	//gEnv->pLog->Log("Updates Enabled");

	//if (gEnv->IsEditorGameMode())
	//{
		Vec3 entCurPos = GetEntity()->GetWorldPos();
		GetEntity()->SetPos(entCurPos + Vec3(0, 0, 0.05));

        if (GetEntity()->GetWorldPos().z > 500 && !bMaterialSwitchedBack) {
            GetEntity()->SetMaterial(m_pmatOriginal);
            bMaterialSwitchedBack = true;
        }
	//}
}

